/******************************************************************************
 * Copyright (C) 2024 EternalChip, Inc.(Gmbh) or its affiliates.
 * 
 * All Rights Reserved.
 * 
 * File name: uart_buffer.h
 * 
 * Description: Provide the registers of AHT21.
 * 
 * Processing flow:
 * 
 * call directly.
 * 
 * 
 * Version: V1.0
 * 
 * Modifications:
 * 
 * Date: 2024-07-09 13:05:10
 * 
 * Author: su 
 * Note: 1 tab == 4 spaces!
 * 
 *****************************************************************************/

//******************************** Includes *********************************//
#ifndef __UART_BUFFER_H__
#define __UART_BUFFER_H__

//******************************** Includes C Library files*********************************//
#include <stdint.h>
#include "uart_buffer_reg.h"
//******************************** define *********************************//
#define MAX 256
#define FRAME_HEAD 0xAA
#define FRAME_END  0xBB

//******************************** struct *********************************//
typedef struct{
	uint8_t    *start_byte;    //第一个字节头帧
    uint8_t    *end_byte;      //最后一个字节尾帧
	uint32_t    length;         //长度
	uint8_t    *payloadBuffer;  //数据地址
	uint8_t     dataxor;        //检验
}uartdata_t;

typedef struct{
	uint8_t    *Buffer_address;
	uint32_t    length;
}sendpack_t;
uint8_t  bufferinit(void);                                  //初始化上述结构体指向buffer
uartdata_t *getbuffer(void);                                //获取bufferhandler
uint32_t get_now_buffer_address(void);                       //获取当前指向得bufferaddress
uint8_t* get_nextbuffer_address(void);                      //获取下一个存储地址
uint8_t  calculateXOR(uint32_t* data, uint8_t length);      //计算校验
uint8_t receive_header_frame(uartdata_t *uartdata);         //解析头帧尾帧
sendpack_t *parsingpack(uartdata_t *uartdata);              //拆包整合数据发送出去
#endif
//__UART_BUFFER_H__
